﻿using System;
using System.Collections;
using UnityEngine;
using UnityEngine.InputSystem;

namespace Assets.Scripts.Manager
{
    public class InputManager : MonoBehaviour
    {
        public static InputManager Instance;

        private PlayerInputActions _inputActions;

        private void Awake()
        {
            _inputActions = new PlayerInputActions();

            if (Instance != null && Instance != this)
            {
                Destroy(gameObject);
                return;
            }
            Instance = this;
            //DontDestroyOnLoad(gameObject);
        }

        private void OnEnable()
        {
            _inputActions.UI.Enable();
            _inputActions.UI.Select.performed += OnSelectClick;
            _inputActions.UI.Start.performed += OnStartClick;
        }
        private void OnDisable()
        {
            _inputActions.UI.Select.performed -= OnSelectClick;
            _inputActions.UI.Start.performed -= OnStartClick;
            _inputActions.UI.Disable();
        }


        public Action OnStartClickEvent;
        private void OnStartClick(InputAction.CallbackContext obj)
        {
        
           OnStartClickEvent?.Invoke();
        }

        public Action OnSelectClickEvent;
        private void OnSelectClick(InputAction.CallbackContext obj)
        {
            OnSelectClickEvent?.Invoke();
        }

       
    }
}